package com.woniu.util;

import org.springframework.data.redis.core.StringRedisTemplate;

import javax.annotation.Resource;

public class RedisKeyUtil {


    @Resource
    private StringRedisTemplate stringRedisTemplate;
    /**
     * 团课排班，团课课程id锁
     * @param classId
     * @return
     */
    public static String scheduleClassIdLock(Integer classId) {
        return "league:class:workforce:lock:class:id:code:"+classId;
    }


        /*
    返回某用户购物车列表的key
    */
    public static String userShopping(Integer userId) {
        return "user:shopping:userId" + userId;
    }



    /*
 返回某用户购物车中某商品信息的key
  */
    public static String shoppingInfo(Integer userId,Integer goodsId){
        return "shoppingInfo:userId:"+userId+":goodsId" +goodsId;
    }


    //注册短信验证码key
    public static String registerCodeKey(String phone) throws Exception {
        return "register:code:phone:" + phone;
    }

    //一分钟是否发送过注册短信key
    public static String registerCodeOnMinute(String phone) throws Exception {
        return "register:code:minute:phone:" + phone;
    }

    //登录短信验证码key
    public static String loginCodeKey(String phone) throws Exception {
        return "login:code:phone:" + phone;
    }

    //一分钟是否发送过登录短信key
    public static String loginCodeOnMinute(String phone) throws Exception {
        return "login:code:minute:phone:" + phone;
    }


    //一小时内发送短信的总次数
    public static String sendNumbers(String phone) throws Exception {
        return "sendCode:number:phone:" + phone;
    }

    //某个用户的书籍收藏列表
    public static String collectBook(Integer userId) throws Exception {
        return "collect:book:userId:" + userId;
    }

    //书籍收藏排行榜
    public static String collectBookRank() throws Exception {
        return "collect:book:rank";
    }

    //图书类别树型数据缓存KEY
    public static String cacheBookTreeType() throws Exception {
        return "cache:bookType:tree";
    }

    //保存用户在平台中的购物车中的商品ID集合KEY
    public static String userShoppingCar(Integer userId) throws Exception {
        return "shopping:car:userId:" + userId;
    }

    //保存用户购物车某一条记录的详细信息KEY
    public static String shoppingCarInfo(Integer userId, Integer bookId) throws Exception {
        return "shopping:car:userId:" + userId + ":bookId:" + bookId;
    }

    //注册用户名锁
    public static String lockRegisterByUsername(String userName) throws Exception {
        return "lock:register:username:" + userName;
    }

    //注册电话锁
    public static String lockRegisterByUserPhone(String userPhone) throws Exception {
        return "lock:register:userPhone:" + userPhone;
    }

    //注册教练名锁
    public static String lockRegisterByCoachname(String coachName) throws Exception {
        return "lock:register:coachName:" + coachName;
    }

    //注册教练电话锁
    public static String lockRegisterByCoachPhone(String coachPhone) throws Exception {
        return "lock:register:coachPhone:" + coachPhone;
    }

    //注册邮箱锁
    public static String lockRegisterByUserEmail(String userEmail) throws Exception {
        return "lock:register:userEmail:" + userEmail;
    }

    //下单锁
    public static String lockOrderGoodsId(Integer goodsId) throws Exception {
        return "lock:order:goodsId:" + goodsId;
    }

    //退款订单锁
    public static String lockOrderRefund(String orderId) throws Exception {
        return "lock:refund:orderId:" + orderId;
    }



    /**
     * 订单支付限时
     */
    public static String payOrderTime(String orderId) {
        return "payOrderTime:" + orderId;
    }

    public static String lockTicketId(Integer id) {
        return "lockTicketId"+id;
    }


    /*
   判断redis中是否存在这个键
    */
    public boolean exist(String key) {
        return stringRedisTemplate.hasKey(key);
    }
}

